package com.up.management.controller;

import com.up.common.annotation.Log;
import com.up.common.core.controller.BaseController;
import com.up.common.core.domain.AjaxResult;
import com.up.common.core.page.TableDataInfo;
import com.up.common.enums.BusinessType;
import com.up.common.utils.poi.ExcelUtil;
import com.up.management.domain.entity.InheritorApplication;
import com.up.management.service.IInheritorApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 传承人申请管理Controller
 * 
 * @author cloud
 * @date 2025-09-22
 */
@RestController
@RequestMapping("/management/InheritorApplication")
public class InheritorApplicationController extends BaseController
{
    @Autowired
    private IInheritorApplicationService inheritorApplicationService;

    /**
     * 查询传承人申请管理列表
     */
    @PreAuthorize("@ss.hasPermi('management:InheritorApplication:list')")
    @GetMapping("/list")
    public TableDataInfo list(InheritorApplication inheritorApplication)
    {
        System.out.println("查询参数 createdAt: " + inheritorApplication.getCreatedAt());
        startPage();
        List<InheritorApplication> list = inheritorApplicationService.selectInheritorApplicationList(inheritorApplication);
        System.out.println("查询结果数量: " + list.size());
        return getDataTable(list);
    }

    /**
     * 导出传承人申请管理列表
     */
    @PreAuthorize("@ss.hasPermi('management:InheritorApplication:export')")
    @Log(title = "传承人申请管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InheritorApplication inheritorApplication)
    {
        List<InheritorApplication> list = inheritorApplicationService.selectInheritorApplicationList(inheritorApplication);
        ExcelUtil<InheritorApplication> util = new ExcelUtil<InheritorApplication>(InheritorApplication.class);
        util.exportExcel(response, list, "传承人申请管理数据");
    }

    /**
     * 获取传承人申请管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('management:InheritorApplication:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(inheritorApplicationService.selectInheritorApplicationById(id));
    }

    /**
     * 新增传承人申请管理
     */
    @PreAuthorize("@ss.hasPermi('management:InheritorApplication:add')")
    @Log(title = "传承人申请管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InheritorApplication inheritorApplication)
    {
        return toAjax(inheritorApplicationService.insertInheritorApplication(inheritorApplication));
    }

    /**
     * 修改传承人申请管理
     */
    @PreAuthorize("@ss.hasPermi('management:InheritorApplication:edit')")
    @Log(title = "传承人申请管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InheritorApplication inheritorApplication)
    {
        return toAjax(inheritorApplicationService.updateInheritorApplication(inheritorApplication));
    }

    /**
     * 审核传承人申请
     */
    @PreAuthorize("@ss.hasPermi('management:InheritorApplication:audit')")
    @Log(title = "传承人申请审核", businessType = BusinessType.UPDATE)
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody InheritorApplication inheritorApplication)
    {
        return toAjax(inheritorApplicationService.auditInheritorApplication(inheritorApplication));
    }

    /**
     * 删除传承人申请管理
     */
    @PreAuthorize("@ss.hasPermi('management:InheritorApplication:remove')")
    @Log(title = "传承人申请管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inheritorApplicationService.deleteInheritorApplicationByIds(ids));
    }
}
